#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<map>
#include<unordered_map>
#include<set>
#include<cstdio>
#include<algorithm>
#define debug(a) cout<<#a<<"="<<a<<endl;
using namespace std;
typedef long long LL;
inline LL read(){LL x=0,f=1;char ch=getchar();	while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;}
const int maxn=1e5+100;
class Solution {
vector<int>v[maxn];
unordered_map<int,int>map1;
int dp[35][35],cnt=0;
public:
    string S;
    int solve(int l,int r)
    {
        if(l==r){
            return (S[l]-'0');
        }
        for(int i=l;i<=r;i++){
            if(S[i]=='+'){
                return solve(l,i-1)+solve(i+1,r);
            }
        }
        for(int i=l;i<=r;i++){
            if(S[i]=='*'){
                return solve(l,i-1)*solve(i+1,r);
            }
        }
    }
    vector<int>& fun(int l,int r)
    {
        if(v[dp[l][r]].size()) return v[dp[l][r]];
        if(l==r){
            dp[l][r]=S[l]-'0';
            v[++cnt].push_back(dp[l][r]);
            return v[cnt-1];
        }
        vector<int>now;vector<int>l1,r1;
        for(int i=l;i<=r;i++){
            if(S[i]=='+'){
                l1=fun(l,i-1);
                r1=fun(i+1,r);
                for(int j=0;j<l1.size();j++){
                    for(int k=0;k<r1.size();k++){
                        if(l1[j]+r1[k]<=1000){
                            now.push_back(l1[j]+r1[k]);
                        }
                    }
                }
            }
            else if(S[i]=='*'){
                l1=fun(l,i-1);
                r1=fun(i+1,r);
                for(int j=0;j<l1.size();j++){
                    for(int k=0;k<r1.size();k++){
                        if(l1[j]*r1[k]<=1000){
                            now.push_back(l1[j]*r1[k]);
                        }
                    }
                }
            }
        }
        sort(now.begin(),now.end());
        now.erase(unique(now.begin(),now.end()),now.end());
        dp[l][r]=++cnt;
        v[cnt]=now;
        return now;
    }
    int scoreOfStudents(string s, vector<int>& answers) {
        S=s;
        int l=0;int r=answers.size()-1;
        int std=solve(l,r);
        vector<int>res=fun(l,r);
        for(int i=0;i<res.size();i++) map1[res[i]]=1;
        int ans=0;
        for(int i=0;i<answers.size();i++){
            if(answers[i]==std){
                ans+=5;
            }
            else if(map1[answers[i]]){
                ans+=2;
            }
        }
        return ans;
    }
};
int main(void){


   	return 0;
}
